#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

#include "class.h"

int main() {
    // 创建智能小车实例
    LaserRadar laserRadar("rad12345678", "RS-Helios-16p", 16, 100, 8);
    Chassis chassis(laserRadar, "dp12345678", "SCOUT MINI", 451, 490, 115, 0, "四轮四驱", 10, 4, "公路轮、麦克纳姆轮", 175);
    AGXKit agxKit("agx12345678", "AGX Xavier", 32, 512, 64, 32, 32);
    StereoCamera stereoCamera("cam12345678", "RealSense D435i", "D430", "1920*1080", 30, "87*58", 90);
    Gyroscope gyroscope("gyr12345678", "CH110", "NXP");
    LCD lcd("lcd12345678", 11.6, "super");
    Battery battery("bat12345678", "24V", "15Ah", "24V", "2H");

    SmartCar car("cqusn001", chassis, agxKit, stereoCamera, laserRadar, gyroscope, lcd, battery);

    // 创建学生实例并分配智能小车
    vector<Student> students;
    students.emplace_back("s001", "赵", car);
    students.emplace_back("s002", "钱", car);
    students.emplace_back("s003", "孙", car);
    students.emplace_back("s004", "李", car);
    students.emplace_back("s005", "周", car);
    students.emplace_back("s006", "吴", car);
    students.emplace_back("s007", "郑", car);
    students.emplace_back("s008", "王", car);
    students.emplace_back("s009", "冯", car);
    students.emplace_back("s010", "陈", car);

    // 输入障碍物状态
    std::string obstacleStatus;
    cout << "请输入障碍物状态（前方/右前方/左前方）: ";
    cin >> obstacleStatus;

    // 通知观察者
    laserRadar.notify(obstacleStatus);

/*
    // 打印信息
    int currentIndex = 0;
    char ch;
    while (true) {
         cout << "Press 'n' for next, 'p' for previous or 'q' to quit: ";
        cin >> ch;
        if (ch == 'n') {
            currentIndex = (currentIndex + 1) % students.size();
        } else if (ch == 'p') {
            currentIndex = (currentIndex - 1 + students.size()) % students.size();
        } else if (ch == 'q') {
            break;
        }
        students[currentIndex].print();
    }
   

    // 保存到文件
    ofstream file("car_info.txt", ios::out);
    if (file.is_open()) {
        students[currentIndex].saveToFile(file);
        file.close();
    } else {
        cout << "无法打开文件进行写入" << endl;
    }
     */
    
    
    return 0;
}